<template>
	<view class="detail">
		<view class="infobox">
			<image v-if="info.img" :src="info.img | getImg" mode="widthFix"></image>
			<view class="info">
				<view class="name">
					{{info.shop_name}}
				</view>
				<view class="gap">
					5.48km
				</view>
				<view class="gap" @click="toAddress()">
					<uni-icons type="location-filled" color="#777"></uni-icons>
					<text>{{info.shop_address}}</text>
				</view>
				<view class="gap" @click="call">
					<uni-icons type="phone" color="#777"></uni-icons>
					<text>{{info.phone}}</text>
				</view>
			</view>
		</view>
		<view class="goods-list">
			<view class="product-list">
				<view class="product" v-for="(goods) in goodsList" :key="goods.id" @tap="toGoods(goods)">
					<image mode="" :src="goods.logo_url |getImg"></image>
					<view class="name">{{goods.name}}</view>
					<view class="info">
						<view class="price">{{goods.price}}</view>
						<view class="slogan">售出:{{goods.sell}}</view>
					</view>
				</view>
			</view>
			<view class="loading-text">{{loadingText}}</view>
		</view>
	</view>
</template>

<script>
	import {
		ShopDetail
	} from "@/api/api.js"

	export default {
		data() {
			return {
				phone: '',
				info: [],
				goodsList: [],
				loadingText: "正在加载...",
			}
		},
		onLoad(e) {
			this.ShopDetail(e.id)
		},
		methods: {

			toAddress() {
				uni.openLocation({
					latitude: Number(this.info.latitude),
					longitude: Number(this.info.longitude),
					address: this.info.shop_address,
					name: this.info.address_name,
					success: (res) => {
						console.log(res);
					},
					fail: (err) => {
						console.log(err);
					}
				})
			},
			ShopDetail(id) {
				ShopDetail({
					id: id
				}).then(res => {
					this.info = res.data
					console.log(res);
				})
			},
			call() {
				uni.makePhoneCall({
					phoneNumber: this.info.phone
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f3f3f3;
	}

	.goods-list {
		.loading-text {
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 60upx;
			color: #979797;
			font-size: 24upx;
		}

		.product-list {
			width: 92%;
			padding: 0 4% 3vw 4%;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.product {
				width: 48%;
				border-radius: 20upx;
				background-color: #fff;
				margin: 0 0 15upx 0;
				box-shadow: 0upx 5upx 25upx rgba(0, 0, 0, 0.1);

				image {
					width: 100%;
					border-radius: 20upx 20upx 0 0;
					height: 160px;
				}

				.name {
					width: 92%;
					padding: 10upx 4%;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					text-align: justify;
					overflow: hidden;
					font-size: 30upx;
					padding-bottom: 0;
				}

				.info {
					display: flex;
					justify-content: space-between;
					align-items: flex-end;
					width: 92%;
					padding: 10upx 4% 10upx 4%;

					.price {
						color: #e65339;
						font-size: 30upx;
						font-weight: 600;
					}

					.slogan {
						color: #807c87;
						font-size: 24upx;
					}
				}
			}

		}
	}

	.infobox {
		background-color: #fff;

		image {
			width: 100%;
		}

		.info {
			padding: 10px;

			.name {
				font-size: 20px;
				paddding: 10px 0;
			}

			.gap {
				color: #777;
				margin-top: 10px;

				text {
					margin-right: 5px;
				}
			}
		}
	}
</style>
